/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2004
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
*
* Author's email :     insane@dees.ufmg.br
* Author's Website :   http://www.dees.ufmg.br/insane
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*
*/

package br.ufmg.dees.insane.commons.view;

import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;

/**
 * A class representing the state of the view.
 * @author  	Penna, Samuel & Pitangueira, Roque
 * @see xyplot_view.InterfaceXYPlot
 * @see xyplot_view.DrawingArea
 * @since    april 2005
 */
public class ViewState implements Serializable {
	
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	private String name = new String("untitled.isn");
	//the model file path
    private transient String path = new String();
    
    //  The number view precision
    private int precision = 2;

    //  The limits of the view
    private double vx = 0;
    private double vy = 0;
    private double vwidth = 10;
    private double vheight = 10;
    
    //The Current zoom of the view
    private double zx = 0;
    private double zy = 0;
    private double zwidth = 10;
    private double zheight = 10;

    //The limits and increments of the grid
    private double gx = 1;
    private double gy = 1;
    private double gwidth = 10;
    private double gheight = 10; 
    private double gxInc = 2;
    private double gyInc = 2;
    public double gridLineWidth = 0.5;
    
    //The snap, grid and boundary existence
    private boolean snap = true;
    private boolean grid = true;
    private boolean distort = true;
    protected boolean boundary = false;
    
    public double boundaryLineWidth = 1.0;
    
    //  The view background color
    public Color bgcolor   = Color.WHITE;    

    //The grid and boundary color
    public Color gridColor = Color.darkGray;   
    public Color boundaryColor = gridColor;   
    
    public ViewState() {
    }
     
    /**
	 * @param  s
	 * @uml.property  name="path"
	 */
    public void setPath(String s) {
        path = s;
    }
    
    /**
	 * @return
	 * @uml.property  name="path"
	 */
    public String getPath() {
        return path;
    }
 
    /**
	 * @param  i
	 * @uml.property  name="precision"
	 */
    public void setPrecision(int i) {
        precision = i;
    }
	
    /**
	 * @return
	 * @uml.property  name="precision"
	 */
    public int getPrecision() {
        return precision;
    }
  
    /**
     * @param lim
     */
    public void setLimits(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        vx = limits.x;
        vy = limits.y;
        vwidth = limits.width;
        vheight = limits.height;
    }
    
    /**
     * @param x
     * @param y
     */
    public void setLimits(double x, double y) {
        this.vx = 0.0;
        this.vy = 0.0;
        vwidth = x;
        vheight = y;
    }
	
    /**
     * @return
     */
    public Rectangle2D.Double getLimits() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = vx;
        limits.y = vy;
        limits.width = vwidth;
        limits.height = vheight;
		return limits;
    }
  
    /**
     * @param lim
     */
    public void setCurrentZoom(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        zx = limits.x;
        zy = limits.y;
        zwidth = limits.width;
        zheight = limits.height;
    }
    
	
    /**
     * @return
     */
    public Rectangle2D.Double getCurrentZoom() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = zx;
        limits.y = zy;
        limits.width = zwidth;
        limits.height = zheight;
        return limits;
    }
   
    /**
	 * @param  is_on
	 * @uml.property  name="grid"
	 */
    public void setGrid(boolean is_on) {
        grid = is_on;
    }
    
    /**
     * @return
     */
    public boolean isGridOn() {
        return grid;
    }
    
     /**
	 * @param boundary  The boundary to set.
	 * @uml.property  name="boundary"
	 */
    public void setBoundary(boolean is_on) {
         boundary = is_on;
     }
     
     
     public boolean isBoundaryOn() {
         return boundary;
     }

    /**
     * @param lim
     */
    public void setGridLimits(Rectangle2D lim) {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.setRect(lim);
        gx = limits.x;
        gy = limits.y;
        gwidth = limits.width;
        gheight = limits.height;
    }
    
    /**
     * @return
     */
    public Rectangle2D.Double getGridLimits() {
        Rectangle2D.Double limits = new Rectangle2D.Double();
        limits.x = gx;
        limits.y = gy;
        limits.width = gwidth;
        limits.height = gheight;
        return limits;
    }   
  
    /**
     * @param x
     * @param y
     */
    public void setGridIncrements(double x, double y) {
        gxInc = x;
        gyInc = y;
    }
    
    /**
     * @return
     */
   public double getGridXInc() {
        return gxInc;
    }
    
    /**
     * @return
     */
    public double getGridYInc() {
        return gyInc;
    }
    
    /**
	 * @param  b
	 * @uml.property  name="snap"
	 */
    public void setSnap(boolean b) {
        snap = b;
    }
    
    /**
     * @return
     */
    public boolean isSnapOn() {
        return snap;
    }

	/**
	 * The method return the name.
	 * @return Returns The name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * The method set the field name from the parameter name.
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	public boolean isDistort() {
		return distort;
	}

	public void setDistort(boolean distort) {
		this.distort = distort;
	}
	
}